{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "application/vnd.databricks.v1+cell": {
     "cellMetadata": {
      "byteLimit": 2048000,
      "rowLimit": 10000
     },
     "inputWidgets": {},
     "nuid": "b3670868-2c9b-40fc-9c8d-4c50d2e0096f",
     "showTitle": false,
     "tableResultSettingsMap": {},
     "title": ""
    }
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Out[2]: [Row(row_num=1, purchase=32488348, redeem=5525022),\n Row(row_num=2, purchase=29037390, redeem=2554548),\n Row(row_num=3, purchase=27270770, redeem=5953867),\n Row(row_num=4, purchase=18321185, redeem=6410729),\n Row(row_num=5, purchase=11648749, redeem=2763587),\n Row(row_num=6, purchase=36751272, redeem=1616635),\n Row(row_num=7, purchase=8962232, redeem=3982735),\n Row(row_num=8, purchase=57258266, redeem=8347729),\n Row(row_num=9, purchase=26798941, redeem=3473059),\n Row(row_num=10, purchase=30696506, redeem=2597169)]"
     ]
    }
   ],
   "source": [
    "from pyspark.sql import SparkSession\n",
    "from pyspark.ml.feature import VectorAssembler\n",
    "from pyspark.ml.regression import LinearRegression\n",
    "from pyspark.ml.evaluation import RegressionEvaluator\n",
    "\n",
    "spark = SparkSession.builder.appName(\"LinearRegressionExample\").getOrCreate()\n",
    "\n",
    "df = spark.read.csv('dbfs:/FileStore/tables/input-3.csv', header=True, inferSchema=True)\n",
    "df.head(10)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "application/vnd.databricks.v1+cell": {
     "cellMetadata": {
      "byteLimit": 2048000,
      "rowLimit": 10000
     },
     "inputWidgets": {},
     "nuid": "4fc44e65-9a26-4a1a-85db-f34dd46ce714",
     "showTitle": false,
     "tableResultSettingsMap": {},
     "title": ""
    }
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "purchase_Coefficients: [677271.1476659866]\npurchase_Intercept: 71904919.26130556\nredeem_Coefficients: [817458.7890098362]\nredeem_Intercept: -4635718.154896537\n"
     ]
    }
   ],
   "source": [
    "assembler = VectorAssembler(inputCols=[\"row_num\"], outputCol=\"features\")\n",
    "df_assembled = assembler.transform(df)\n",
    "\n",
    "#分别训练purchase和redeem\n",
    "lr1 = LinearRegression(featuresCol=\"features\", labelCol=\"purchase\")\n",
    "model1 = lr1.fit(df_assembled)\n",
    "\n",
    "lr2 = LinearRegression(featuresCol=\"features\", labelCol=\"redeem\")\n",
    "model2 = lr2.fit(df_assembled)\n",
    "\n",
    "#线性模型的系数和截距\n",
    "print(\"purchase_Coefficients: %s\" % str(model1.coefficients))\n",
    "print(\"purchase_Intercept: %s\" % str(model1.intercept))\n",
    "print(\"redeem_Coefficients: %s\" % str(model2.coefficients))\n",
    "print(\"redeem_Intercept: %s\" % str(model2.intercept))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "application/vnd.databricks.v1+cell": {
     "cellMetadata": {
      "byteLimit": 2048000,
      "rowLimit": 10000
     },
     "inputWidgets": {},
     "nuid": "186baa76-7bf8-4aeb-b571-6f4025dc1616",
     "showTitle": false,
     "tableResultSettingsMap": {},
     "title": ""
    }
   },
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<style scoped>\n",
       "  .table-result-container {\n",
       "    max-height: 300px;\n",
       "    overflow: auto;\n",
       "  }\n",
       "  table, th, td {\n",
       "    border: 1px solid black;\n",
       "    border-collapse: collapse;\n",
       "  }\n",
       "  th, td {\n",
       "    padding: 5px;\n",
       "  }\n",
       "  th {\n",
       "    text-align: left;\n",
       "  }\n",
       "</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>row_num</th><th>prediction</th></tr></thead><tbody><tr><td>428</td><td>3.617769704623478E8</td></tr><tr><td>429</td><td>3.624542416100138E8</td></tr><tr><td>430</td><td>3.631315127576798E8</td></tr><tr><td>431</td><td>3.638087839053458E8</td></tr><tr><td>432</td><td>3.644860550530118E8</td></tr><tr><td>433</td><td>3.6516332620067775E8</td></tr><tr><td>434</td><td>3.6584059734834373E8</td></tr><tr><td>435</td><td>3.665178684960097E8</td></tr><tr><td>436</td><td>3.671951396436757E8</td></tr><tr><td>437</td><td>3.678724107913417E8</td></tr><tr><td>438</td><td>3.685496819390077E8</td></tr><tr><td>439</td><td>3.692269530866737E8</td></tr><tr><td>440</td><td>3.6990422423433965E8</td></tr><tr><td>441</td><td>3.7058149538200563E8</td></tr><tr><td>442</td><td>3.712587665296716E8</td></tr><tr><td>443</td><td>3.719360376773376E8</td></tr><tr><td>444</td><td>3.726133088250036E8</td></tr><tr><td>445</td><td>3.732905799726696E8</td></tr><tr><td>446</td><td>3.739678511203356E8</td></tr><tr><td>447</td><td>3.7464512226800156E8</td></tr><tr><td>448</td><td>3.7532239341566753E8</td></tr><tr><td>449</td><td>3.759996645633335E8</td></tr><tr><td>450</td><td>3.7667693571099955E8</td></tr><tr><td>451</td><td>3.773542068586655E8</td></tr><tr><td>452</td><td>3.780314780063315E8</td></tr><tr><td>453</td><td>3.787087491539975E8</td></tr><tr><td>454</td><td>3.7938602030166346E8</td></tr><tr><td>455</td><td>3.8006329144932944E8</td></tr><tr><td>456</td><td>3.807405625969954E8</td></tr><tr><td>457</td><td>3.8141783374466145E8</td></tr></tbody></table></div>"
      ]
     },
     "metadata": {
      "application/vnd.databricks.v1+output": {
       "addedWidgets": {},
       "aggData": [],
       "aggError": "",
       "aggOverflow": false,
       "aggSchema": [],
       "aggSeriesLimitReached": false,
       "aggType": "",
       "arguments": {},
       "columnCustomDisplayInfos": {},
       "data": [
        [
         428,
         3.617769704623478E8
        ],
        [
         429,
         3.624542416100138E8
        ],
        [
         430,
         3.631315127576798E8
        ],
        [
         431,
         3.638087839053458E8
        ],
        [
         432,
         3.644860550530118E8
        ],
        [
         433,
         3.6516332620067775E8
        ],
        [
         434,
         3.6584059734834373E8
        ],
        [
         435,
         3.665178684960097E8
        ],
        [
         436,
         3.671951396436757E8
        ],
        [
         437,
         3.678724107913417E8
        ],
        [
         438,
         3.685496819390077E8
        ],
        [
         439,
         3.692269530866737E8
        ],
        [
         440,
         3.6990422423433965E8
        ],
        [
         441,
         3.7058149538200563E8
        ],
        [
         442,
         3.712587665296716E8
        ],
        [
         443,
         3.719360376773376E8
        ],
        [
         444,
         3.726133088250036E8
        ],
        [
         445,
         3.732905799726696E8
        ],
        [
         446,
         3.739678511203356E8
        ],
        [
         447,
         3.7464512226800156E8
        ],
        [
         448,
         3.7532239341566753E8
        ],
        [
         449,
         3.759996645633335E8
        ],
        [
         450,
         3.7667693571099955E8
        ],
        [
         451,
         3.773542068586655E8
        ],
        [
         452,
         3.780314780063315E8
        ],
        [
         453,
         3.787087491539975E8
        ],
        [
         454,
         3.7938602030166346E8
        ],
        [
         455,
         3.8006329144932944E8
        ],
        [
         456,
         3.807405625969954E8
        ],
        [
         457,
         3.8141783374466145E8
        ]
       ],
       "datasetInfos": [],
       "dbfsResultPath": null,
       "isJsonSchema": true,
       "metadata": {},
       "overflow": false,
       "plotOptions": {
        "customPlotOptions": {},
        "displayType": "table",
        "pivotAggregation": null,
        "pivotColumns": null,
        "xColumns": null,
        "yColumns": null
       },
       "removedWidgets": [],
       "schema": [
        {
         "metadata": "{}",
         "name": "row_num",
         "type": "\"long\""
        },
        {
         "metadata": "{\"ml_attr\":{}}",
         "name": "prediction",
         "type": "\"double\""
        }
       ],
       "type": "table"
      }
     },
     "output_type": "display_data"
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<style scoped>\n",
       "  .table-result-container {\n",
       "    max-height: 300px;\n",
       "    overflow: auto;\n",
       "  }\n",
       "  table, th, td {\n",
       "    border: 1px solid black;\n",
       "    border-collapse: collapse;\n",
       "  }\n",
       "  th, td {\n",
       "    padding: 5px;\n",
       "  }\n",
       "  th {\n",
       "    text-align: left;\n",
       "  }\n",
       "</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>row_num</th><th>prediction</th></tr></thead><tbody><tr><td>428</td><td>3.452366435413133E8</td></tr><tr><td>429</td><td>3.4605410233032316E8</td></tr><tr><td>430</td><td>3.4687156111933297E8</td></tr><tr><td>431</td><td>3.4768901990834284E8</td></tr><tr><td>432</td><td>3.4850647869735265E8</td></tr><tr><td>433</td><td>3.493239374863625E8</td></tr><tr><td>434</td><td>3.501413962753723E8</td></tr><tr><td>435</td><td>3.509588550643822E8</td></tr><tr><td>436</td><td>3.51776313853392E8</td></tr><tr><td>437</td><td>3.525937726424018E8</td></tr><tr><td>438</td><td>3.534112314314117E8</td></tr><tr><td>439</td><td>3.542286902204215E8</td></tr><tr><td>440</td><td>3.5504614900943136E8</td></tr><tr><td>441</td><td>3.558636077984412E8</td></tr><tr><td>442</td><td>3.5668106658745104E8</td></tr><tr><td>443</td><td>3.5749852537646085E8</td></tr><tr><td>444</td><td>3.583159841654707E8</td></tr><tr><td>445</td><td>3.591334429544805E8</td></tr><tr><td>446</td><td>3.5995090174349034E8</td></tr><tr><td>447</td><td>3.607683605325002E8</td></tr><tr><td>448</td><td>3.6158581932151E8</td></tr><tr><td>449</td><td>3.624032781105199E8</td></tr><tr><td>450</td><td>3.632207368995297E8</td></tr><tr><td>451</td><td>3.6403819568853956E8</td></tr><tr><td>452</td><td>3.648556544775494E8</td></tr><tr><td>453</td><td>3.6567311326655924E8</td></tr><tr><td>454</td><td>3.6649057205556905E8</td></tr><tr><td>455</td><td>3.673080308445789E8</td></tr><tr><td>456</td><td>3.6812548963358873E8</td></tr><tr><td>457</td><td>3.6894294842259854E8</td></tr></tbody></table></div>"
      ]
     },
     "metadata": {
      "application/vnd.databricks.v1+output": {
       "addedWidgets": {},
       "aggData": [],
       "aggError": "",
       "aggOverflow": false,
       "aggSchema": [],
       "aggSeriesLimitReached": false,
       "aggType": "",
       "arguments": {},
       "columnCustomDisplayInfos": {},
       "data": [
        [
         428,
         3.452366435413133E8
        ],
        [
         429,
         3.4605410233032316E8
        ],
        [
         430,
         3.4687156111933297E8
        ],
        [
         431,
         3.4768901990834284E8
        ],
        [
         432,
         3.4850647869735265E8
        ],
        [
         433,
         3.493239374863625E8
        ],
        [
         434,
         3.501413962753723E8
        ],
        [
         435,
         3.509588550643822E8
        ],
        [
         436,
         3.51776313853392E8
        ],
        [
         437,
         3.525937726424018E8
        ],
        [
         438,
         3.534112314314117E8
        ],
        [
         439,
         3.542286902204215E8
        ],
        [
         440,
         3.5504614900943136E8
        ],
        [
         441,
         3.558636077984412E8
        ],
        [
         442,
         3.5668106658745104E8
        ],
        [
         443,
         3.5749852537646085E8
        ],
        [
         444,
         3.583159841654707E8
        ],
        [
         445,
         3.591334429544805E8
        ],
        [
         446,
         3.5995090174349034E8
        ],
        [
         447,
         3.607683605325002E8
        ],
        [
         448,
         3.6158581932151E8
        ],
        [
         449,
         3.624032781105199E8
        ],
        [
         450,
         3.632207368995297E8
        ],
        [
         451,
         3.6403819568853956E8
        ],
        [
         452,
         3.648556544775494E8
        ],
        [
         453,
         3.6567311326655924E8
        ],
        [
         454,
         3.6649057205556905E8
        ],
        [
         455,
         3.673080308445789E8
        ],
        [
         456,
         3.6812548963358873E8
        ],
        [
         457,
         3.6894294842259854E8
        ]
       ],
       "datasetInfos": [],
       "dbfsResultPath": null,
       "isJsonSchema": true,
       "metadata": {},
       "overflow": false,
       "plotOptions": {
        "customPlotOptions": {},
        "displayType": "table",
        "pivotAggregation": null,
        "pivotColumns": null,
        "xColumns": null,
        "yColumns": null
       },
       "removedWidgets": [],
       "schema": [
        {
         "metadata": "{}",
         "name": "row_num",
         "type": "\"long\""
        },
        {
         "metadata": "{\"ml_attr\":{}}",
         "name": "prediction",
         "type": "\"double\""
        }
       ],
       "type": "table"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from pyspark.sql.types import StructType, StructField, IntegerType, FloatType\n",
    "\n",
    "# 创建DataFrame，包含接下来30个数据的索引\n",
    "p_future_data = [(i,) for i in range(df.count()+1, df.count()+31)]\n",
    "p_future_df = spark.createDataFrame(p_future_data, [\"row_num\"])\n",
    "r_future_data = [(i,) for i in range(df.count()+1, df.count()+31)]\n",
    "r_future_df = spark.createDataFrame(r_future_data, [\"row_num\"])\n",
    "\n",
    "# 使用同样的VectorAssembler转换数据\n",
    "p_future_df_assembled = assembler.transform(p_future_df)\n",
    "r_future_df_assembled = assembler.transform(r_future_df)\n",
    "\n",
    "# 进行预测\n",
    "purchase_predictions = model1.transform(p_future_df_assembled)\n",
    "redeem_predictions = model2.transform(r_future_df_assembled)\n",
    "\n",
    "display(purchase_predictions.select(\"row_num\", \"prediction\"))\n",
    "display(redeem_predictions.select(\"row_num\", \"prediction\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "application/vnd.databricks.v1+cell": {
     "cellMetadata": {
      "byteLimit": 2048000,
      "rowLimit": 10000
     },
     "inputWidgets": {},
     "nuid": "c5a4d169-a6a5-4e2c-8131-1e35a572c950",
     "showTitle": false,
     "tableResultSettingsMap": {},
     "title": ""
    }
   },
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<style scoped>\n",
       "  .table-result-container {\n",
       "    max-height: 300px;\n",
       "    overflow: auto;\n",
       "  }\n",
       "  table, th, td {\n",
       "    border: 1px solid black;\n",
       "    border-collapse: collapse;\n",
       "  }\n",
       "  th, td {\n",
       "    padding: 5px;\n",
       "  }\n",
       "  th {\n",
       "    text-align: left;\n",
       "  }\n",
       "</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>row_num</th><th>prediction</th></tr></thead><tbody><tr><td>428</td><td>361776970</td></tr><tr><td>429</td><td>362454241</td></tr><tr><td>430</td><td>363131512</td></tr><tr><td>431</td><td>363808783</td></tr><tr><td>432</td><td>364486055</td></tr><tr><td>433</td><td>365163326</td></tr><tr><td>434</td><td>365840597</td></tr><tr><td>435</td><td>366517868</td></tr><tr><td>436</td><td>367195139</td></tr><tr><td>437</td><td>367872410</td></tr><tr><td>438</td><td>368549681</td></tr><tr><td>439</td><td>369226953</td></tr><tr><td>440</td><td>369904224</td></tr><tr><td>441</td><td>370581495</td></tr><tr><td>442</td><td>371258766</td></tr><tr><td>443</td><td>371936037</td></tr><tr><td>444</td><td>372613308</td></tr><tr><td>445</td><td>373290579</td></tr><tr><td>446</td><td>373967851</td></tr><tr><td>447</td><td>374645122</td></tr><tr><td>448</td><td>375322393</td></tr><tr><td>449</td><td>375999664</td></tr><tr><td>450</td><td>376676935</td></tr><tr><td>451</td><td>377354206</td></tr><tr><td>452</td><td>378031478</td></tr><tr><td>453</td><td>378708749</td></tr><tr><td>454</td><td>379386020</td></tr><tr><td>455</td><td>380063291</td></tr><tr><td>456</td><td>380740562</td></tr><tr><td>457</td><td>381417833</td></tr></tbody></table></div>"
      ]
     },
     "metadata": {
      "application/vnd.databricks.v1+output": {
       "addedWidgets": {},
       "aggData": [],
       "aggError": "",
       "aggOverflow": false,
       "aggSchema": [],
       "aggSeriesLimitReached": false,
       "aggType": "",
       "arguments": {},
       "columnCustomDisplayInfos": {},
       "data": [
        [
         428,
         361776970
        ],
        [
         429,
         362454241
        ],
        [
         430,
         363131512
        ],
        [
         431,
         363808783
        ],
        [
         432,
         364486055
        ],
        [
         433,
         365163326
        ],
        [
         434,
         365840597
        ],
        [
         435,
         366517868
        ],
        [
         436,
         367195139
        ],
        [
         437,
         367872410
        ],
        [
         438,
         368549681
        ],
        [
         439,
         369226953
        ],
        [
         440,
         369904224
        ],
        [
         441,
         370581495
        ],
        [
         442,
         371258766
        ],
        [
         443,
         371936037
        ],
        [
         444,
         372613308
        ],
        [
         445,
         373290579
        ],
        [
         446,
         373967851
        ],
        [
         447,
         374645122
        ],
        [
         448,
         375322393
        ],
        [
         449,
         375999664
        ],
        [
         450,
         376676935
        ],
        [
         451,
         377354206
        ],
        [
         452,
         378031478
        ],
        [
         453,
         378708749
        ],
        [
         454,
         379386020
        ],
        [
         455,
         380063291
        ],
        [
         456,
         380740562
        ],
        [
         457,
         381417833
        ]
       ],
       "datasetInfos": [],
       "dbfsResultPath": null,
       "isJsonSchema": true,
       "metadata": {},
       "overflow": false,
       "plotOptions": {
        "customPlotOptions": {},
        "displayType": "table",
        "pivotAggregation": null,
        "pivotColumns": null,
        "xColumns": null,
        "yColumns": null
       },
       "removedWidgets": [],
       "schema": [
        {
         "metadata": "{}",
         "name": "row_num",
         "type": "\"long\""
        },
        {
         "metadata": "{}",
         "name": "prediction",
         "type": "\"integer\""
        }
       ],
       "type": "table"
      }
     },
     "output_type": "display_data"
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<style scoped>\n",
       "  .table-result-container {\n",
       "    max-height: 300px;\n",
       "    overflow: auto;\n",
       "  }\n",
       "  table, th, td {\n",
       "    border: 1px solid black;\n",
       "    border-collapse: collapse;\n",
       "  }\n",
       "  th, td {\n",
       "    padding: 5px;\n",
       "  }\n",
       "  th {\n",
       "    text-align: left;\n",
       "  }\n",
       "</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>row_num</th><th>prediction</th></tr></thead><tbody><tr><td>428</td><td>345236643</td></tr><tr><td>429</td><td>346054102</td></tr><tr><td>430</td><td>346871561</td></tr><tr><td>431</td><td>347689019</td></tr><tr><td>432</td><td>348506478</td></tr><tr><td>433</td><td>349323937</td></tr><tr><td>434</td><td>350141396</td></tr><tr><td>435</td><td>350958855</td></tr><tr><td>436</td><td>351776313</td></tr><tr><td>437</td><td>352593772</td></tr><tr><td>438</td><td>353411231</td></tr><tr><td>439</td><td>354228690</td></tr><tr><td>440</td><td>355046149</td></tr><tr><td>441</td><td>355863607</td></tr><tr><td>442</td><td>356681066</td></tr><tr><td>443</td><td>357498525</td></tr><tr><td>444</td><td>358315984</td></tr><tr><td>445</td><td>359133442</td></tr><tr><td>446</td><td>359950901</td></tr><tr><td>447</td><td>360768360</td></tr><tr><td>448</td><td>361585819</td></tr><tr><td>449</td><td>362403278</td></tr><tr><td>450</td><td>363220736</td></tr><tr><td>451</td><td>364038195</td></tr><tr><td>452</td><td>364855654</td></tr><tr><td>453</td><td>365673113</td></tr><tr><td>454</td><td>366490572</td></tr><tr><td>455</td><td>367308030</td></tr><tr><td>456</td><td>368125489</td></tr><tr><td>457</td><td>368942948</td></tr></tbody></table></div>"
      ]
     },
     "metadata": {
      "application/vnd.databricks.v1+output": {
       "addedWidgets": {},
       "aggData": [],
       "aggError": "",
       "aggOverflow": false,
       "aggSchema": [],
       "aggSeriesLimitReached": false,
       "aggType": "",
       "arguments": {},
       "columnCustomDisplayInfos": {},
       "data": [
        [
         428,
         345236643
        ],
        [
         429,
         346054102
        ],
        [
         430,
         346871561
        ],
        [
         431,
         347689019
        ],
        [
         432,
         348506478
        ],
        [
         433,
         349323937
        ],
        [
         434,
         350141396
        ],
        [
         435,
         350958855
        ],
        [
         436,
         351776313
        ],
        [
         437,
         352593772
        ],
        [
         438,
         353411231
        ],
        [
         439,
         354228690
        ],
        [
         440,
         355046149
        ],
        [
         441,
         355863607
        ],
        [
         442,
         356681066
        ],
        [
         443,
         357498525
        ],
        [
         444,
         358315984
        ],
        [
         445,
         359133442
        ],
        [
         446,
         359950901
        ],
        [
         447,
         360768360
        ],
        [
         448,
         361585819
        ],
        [
         449,
         362403278
        ],
        [
         450,
         363220736
        ],
        [
         451,
         364038195
        ],
        [
         452,
         364855654
        ],
        [
         453,
         365673113
        ],
        [
         454,
         366490572
        ],
        [
         455,
         367308030
        ],
        [
         456,
         368125489
        ],
        [
         457,
         368942948
        ]
       ],
       "datasetInfos": [],
       "dbfsResultPath": null,
       "isJsonSchema": true,
       "metadata": {},
       "overflow": false,
       "plotOptions": {
        "customPlotOptions": {},
        "displayType": "table",
        "pivotAggregation": null,
        "pivotColumns": null,
        "xColumns": null,
        "yColumns": null
       },
       "removedWidgets": [],
       "schema": [
        {
         "metadata": "{}",
         "name": "row_num",
         "type": "\"long\""
        },
        {
         "metadata": "{}",
         "name": "prediction",
         "type": "\"integer\""
        }
       ],
       "type": "table"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from pyspark.sql.functions import col\n",
    "\n",
    "#转化为整数类型\n",
    "p_predictions_with_integers = purchase_predictions.withColumn(\"prediction\", col(\"prediction\").cast(\"int\"))\n",
    "r_predictions_with_integers = redeem_predictions.withColumn(\"prediction\", col(\"prediction\").cast(\"int\"))\n",
    "\n",
    "# 显示结果\n",
    "display(p_predictions_with_integers.select('row_num','prediction'))\n",
    "display(r_predictions_with_integers.select('row_num','prediction'))"
   ]
  }
 ],
 "metadata": {
  "application/vnd.databricks.v1+notebook": {
   "dashboards": [],
   "environmentMetadata": null,
   "language": "python",
   "notebookMetadata": {
    "pythonIndentUnit": 4
   },
   "notebookName": "资金量预测",
   "widgets": {}
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
